package com.tct.worktimeboard.util;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Huhailong
 * @Description List工具类
 * @Date 2021/5/11.
 */
public class ListUtil {

    /**
     * 分割list
     * @param max 每个list最大长度
     * @return 返回分割结果
     */
    public static List<List<String>> cutApart(int max, List<String> list){
        List<List<String>> resultList = new ArrayList<>();
        Stream.iterate(0, n->n+1).limit(countStep(list.size(), max)).forEach(i->{
            resultList.add(list.stream().skip(i*max).limit(max).collect(Collectors.toList()));
        });
//        List<List<Integer>> mgList2 = Stream.iterate(0,n->n+1).limit(countStep(testList.size())).parallel().map(a->testList.stream().skip(a*max).limit(max).parallel().collect(Collectors.toList())).collect(Collectors.toList());;
        return resultList;
    }

    private static Integer countStep(int size, int max){
        return (size + max - 1) / max;
    }
}
